from django.urls import include, path
from .api.v1.views import AddressViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'addresses', AddressViewSet, basename='address')

urlpatterns = [
    # 地址列表 & 创建地址
    path('addresses/', AddressViewSet.as_view({
        'get': 'list',
        'post': 'create'
    }), name='address-list'),
    
    # 地址详情 & 更新 & 删除
    path('addresses/<int:pk>/', AddressViewSet.as_view({
        'get': 'retrieve',
        'put': 'update',
        'patch': 'partial_update',
        'delete': 'destroy'
    }), name='address-detail'),
    
    # 添加用户地址 (自定义端点)
    path('addresses/add-user-address/', AddressViewSet.as_view({
        'post': 'add_user_address'
    }), name='add-user-address'),
    
    # 设置默认地址
    path('addresses/<int:pk>/set-default/', AddressViewSet.as_view({
        'patch': 'set_default_address'
    }), name='set-default-address'),
    
    # 包含视图集自动生成的路由
    path('', include(router.urls)),
]